package spark.core.scala

import org.apache.spark.{SparkContext, SparkConf}

/**
 * 广播变量
 */
object BroadcastVariable {

  def main(args: Array[String]) {
    val conf = new SparkConf()
      .setMaster("local")
      .setAppName("BroadcastVariable")
    val sc = new SparkContext(conf)
    val factor = 3;
    val factorBroadcast = sc.broadcast(factor)
    val list = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    val numbers = sc.parallelize(list)
    val listRDD = numbers.map(x => x * factorBroadcast.value)
    listRDD.foreach(println)
  }
}
